
Mulasha Sinae
Amarr Kismet Foundation Exxxotic
|
Posted - 2008.10.15 00:00:00 -
[1]
When using XmlDocument, you have to be specific as to what nodes you're getting. From that code, you're just getting a list of the nodes that are named "characterID," etc.
Here's how you would do it, although you would want to check for NullReferenceExceptions, because if the node doesn't exist, you get a nasty error.
Sample XML: <CharacterSheet> __<result> ____<characterID>133713371337</characterID> ____<name>MAI NAEM IZ JIMMY</name> ____<race>Cat</race> ____<bloodLine>LOL</bloodLine> ____<gender>Male</gender> __</result> </CharacterSheet>
XmlDocument xml = new XmlDocument(); xml.LoadXml(s);
// This will get all the child nodes under the node <result />, // which will be for most of the API responses. XmlNode node = xml.GetElementsByTagName("result");
// Despite "node" looking like a single node, it is actually an // array that holds a bunch of other XmlNodes (or XmlElements). string characterId = node["characterID"].InnerText; string name = node["name"].InnerText; string race = node["race"].InnerText; string bloodline = node["bloodLine"].InnerText; string gender = node["gender"].InnerText;
Polymorphism comes into play a lot when using XmlDocument. You can use XmlNode, or XmlElement. I usually use XmlNode, although XmlElement seems better in the long run because XmlElement has the GetElementsByTagName method.
There is a bit of a more graceful way of doing it with XmlReader, but you can google that yourself. To access node attributes, for use in responses such as MemberTracking, just do the exact same thing, except with "node.Attributes["ATTRIBUTENAME"].InnerText;"
For example: <row characterID="133713371337" name="MAI NAEM IZ JIMMY" race="Cat" bloodLine="LOL" gender="Male" />
foreach (XmlNode node in xml.GetElementsByTagName("row")) { _____string characterId = node.Attributes["characterID"].InnerText; _____// Etc... }
Hope this helped!
|

Mulasha Sinae
Amarr Kismet Foundation Exxxotic
|
Posted - 2008.10.15 10:47:00 -
[2]
Originally by: Vistilantus edit - the part "string characterId = node["characterID"].InnerText;" node[] looks for an integer value which is why it wouldn't work straight up. obvisouly, i would prefer a way of retrieving the data by using the "name of field here" so any help on this would be appreciated. I just got the linkage for the EVEDev wiki so i`m gonna have a looksie there and see what i can find.
I'm sorry, I left out one crucial thing in my code example.
In my first post, if you replace:
XmlNode node = xml.GetElementsByTagName("result");
with:
XmlNode node = xml.GetElementsByTagName("result")[0];
it should compile and allow you to use field names.
|